<script setup>
import { useRequest } from '@/hooks/requestHooks.js';
import { useWatch } from '@/hooks/useWatch.js';
import { getTreeData } from '@/api/index.js';
import SearchEnterprise from '@/components/EnterpriseInfo/SearchEnterprise.vue';
import EnterpriseTree from '@/components/EnterpriseInfo/EnterpriseTree.vue';
const queryParams = ref({
  enterpriseCode: '1',
});
const data = ref([]);
const [res, loading, run] = useRequest(getTreeData, {
  defaultParams: [queryParams.value],
  manual: true,
});
const checkedChange = val => {
  queryParams.value.enterpriseCode = val?.enterpriseCode;
  run(queryParams.value);
};
useWatch(res, n => {
  data.value = n;
});
const addBuilding = () => {
  run(queryParams.value);
};
</script>
<template>
  <div class="u-df-st architecture-box">
    <div class="architecture-left u-base-fg u-h100 u-br20 u-border-bg">
      <SearchEnterprise v-loading="loading" @checkedChange="checkedChange" :isDefaultSelect="true" />
    </div>
    <div class="architecture-right u-base-fg u-h100">
      <EnterpriseTree
        @addBuilding="addBuilding"
        :data="data"
        :qybh="queryParams.enterpriseCode"
        :defaultData="data"
        :showOperate="true"
        :addTop="true"
      />
    </div>
  </div>
</template>
<style lang="scss" scoped></style>
